
window.onload = function() {
  var show = document.getElementById("show_time");
  setInterval(function() {
    var time = new Date();
    var hours = time.getHours();
    var minutes = time.getMinutes();
    var second = time.getSeconds();
    if(minutes<10){
    	minutes = "0"+minutes;
    }
    if(second<10){
    	second = "0"+second;
    }
    var t = hours + ":" + minutes+":"+second;
   	show.innerHTML = "当前时间："+t;
  }, 1000);
 };
$(function(){ 
	odd_even(".activity_ul");
	odd_even(".remind_ul");
	odd_even(".live_url");
	odd_even(".heal_url");
});
//奇偶行样式
function odd_even(cla){ 
	$(cla).find("li").each(function(index,element){ 
		if(index%2==1){
			$(this).addClass("even"); 
		}else{
			$(this).addClass("odd"); 
		} 
	}); 
} 
//-----------添加快捷入口
//弹框
function addShow(){
	reloadQuick(0);
	$(".celAdd").each(function(){
		$(this).next().remove(); 
	}) 
	showPopC('dialog_0');
}
function setlAdd(obj){
	var moduleCode = $(obj).attr("moduleCode");
	var optionCode = $(obj).attr("optionCode");
	$.ajax({
		type:"POST",
		dataType:"json",
		url:"../platform/createQuick",
		data:{
			moduleCode:moduleCode,
			optionCode:optionCode
		},
		async:false,
		success:function(data){
			if(data.data){
				$(obj).text("取消添加").removeClass().addClass("btn_gray_sm").attr("onclick","cancelAdd(this)").attr("quickId",data.id)
		  		$(obj).parents("tr").find("font.module_status").text("已添加");
				reloadQuick();
			}else{
				if(data.message){
					zhyAlert(data.message);
				}else{
					zhyAlert("添加失败");
				}
			}
		}
	})
}
//-----------取消快捷入口
function cancelAdd(obj){//快捷入口 取消添加
	var id = $(obj).attr("quickId");
	var moduleCode = $(obj).attr("moduleCode");
	var optionCode = $(obj).attr("optionCode");
	$.ajax({
		type:"POST",
		dataType:"json",
		url:"../platform/delQuick",
		data:{
			id:id,
			moduleCode:moduleCode,
			optionCode:optionCode
		},
		async:false,
		success:function(data){
			if(data.data){
				$(obj).text("添加").removeClass().addClass("btn_blue_sm").attr("onclick","setlAdd(this)")
		  		$(obj).parents("tr").find("font.module_status").text("");
				reloadQuick();
			}else{
				if(data.message){
					zhyAlert(data.message);
				}else{
					zhyAlert("取消失败");
				}
			}
		}
	})
}
//局部加载快捷入住
function reloadQuick(num){
	$.ajax({
		type:"POST",
		dataType:"html",
		url:"../platform/platformJSPShow",
		data:{
			num:num
		},
		async:false,
		success:function(data){
			if(num==0){
				$("#addShow").empty().html(data);
			}else{
				$("#showQuick").empty().html(data);
				setQuicEntry(); 
			}
		}
	})
}
function setQuicEntry(){//快捷入口 滚动
		var w = 120,
		    l = $(".quick_entry li").length;
	    $(".quick_entry li").eq(l-1).css("margin-right","0px");
	    if($(".quick_entry").width()<w*l){
	    	$(".quick_entry").css("overflow-x","scroll");
	    }else{
	    	$(".quick_entry").css("overflow-x","hidden");
	    }
		$(".quick_entry ul").width(w*l)
	}
	function saveAdd(obj){//快捷入口 保存添加
		var html="";
		$('#module_list').find(".btn_gray_sm").each(function(){
			var name=$(this).parents("tr").find(".module_name").text();
			var classname=$(this).parents("tr").find("i").attr("class");
				html+="<li class=\"zhy_gn_block\">"+
        			"<a href=\"\">"+
        				"<div class=\"quick_entry_bg\">"+
        					"<div>"+
        				 		"<i class=\""+classname+"\"></i>"+
        					"</div>"+
        				"</div>"+
        				"<p>"+name+"</p>"+
        			"</a>"+
        		"</li>"	;
			
		})
		$(".quick_entry ul").html(html);
		setQuicEntry();
		hidePopC()
	}
	
	setQuicEntry();
	$(window).resize(function(){
		setQuicEntry();
	}) 
	//日历 
	var year= new Date().getFullYear();
  	var mon=  new Date().getMonth()+1;
  	$("#choose_year").text(year);
  	$("#choose_mon").text(mon);
	setYearDay(year,mon)
function setYearDay(year,month){
			//获取年份
		var year = year;
		//获取当前月份
		var month = month;
		//定义当月的天数；
		var days ;
		//当月份为二月时，根据闰年还是非闰年判断天数
		if(month == 2){
		        days= year % 4 == 0 ? 29 : 28;
		}else if(month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12){
		   //月份为：1,3,5,7,8,10,12 时，为大月.则天数为31；
		  days= 31;
		}else{
		  //其他月份，天数为：30.
		  days= 30;
		}
	  //输出天数
      month=month<10?0+month:month;
	  var first_day=new Date(year+"-"+month+"-"+'01').getDay();
	  
	   var year_now=new Date().getFullYear(); 
	   var month_now=new Date().getMonth()+1; 
	  
	  var date_now=new Date().getDate(); 
	  var html=''
	  for(var i =0 ;i<first_day;i++){
	  	 html+='<li><em>&nbsp;</em></li>'
	  }
	  for(var i= 1; i<=days;i++){
	  	if(year_now==year&&month_now==mon&&i==date_now){
	  		html+='<li class="on"><em>'+i+'</em></li>'
	  	}else{
	  	    html+='<li><em>'+i+'</em></li>'
	  	}
	  }
	  $(".zhy_date_ulb").html(html)
}
$("#month_prev").click(function(){
	mon--;
	if(mon<=0){
		year--;
		mon=mon+12;
	}
	$("#choose_year").text(year)
	$("#choose_mon").text(mon)
	setYearDay(year,mon);
})
$("#month_next").click(function(){
	mon++;
	if(mon>=13){
		year++;
		mon=mon-12;
	}
	$("#choose_year").text(year)
	$("#choose_mon").text(mon)
	setYearDay(year,mon);
})
////////////////////////////////////////////监听健康跟安全预警实时消息
$(function(){
	var stationCode = $("#stationCode").val();
	var source="health_remind_"+stationCode;
	parent.listen(source,{
		ondata:function(data){
			handlerHealthRemind(data);
		},
		listenCallback:function(rel){
			if(rel==1){
				//监听成功
			}else{
				//监听失败
			}
		}
	})
});
function handlerHealthRemind(data){
	var jsonObj =  jQuery.parseJSON(data);
	var remindState = jsonObj.remindState;
	if(remindState==0){//健康
		//局部加载健康预警
		var url = "../platform/reloadRemind";
		var id = "#showHealth";
		var remindState = 0;
		reloadRemain(url,id,remindState); 
	}else if(remindState==1||remindState==2||remindState==3){//安全
		//局部加载安全预警
		var url = "../platform/reloadRemind";
		var id = "#showSecurity";
		var remindState = -1;
		reloadRemain(url,id,remindState); 
	}else if(remindState==4||remindState==6){//入住+财务废除
		//局部加载入住预警
		var url = "../platform/reloadRemind";
		var id = "#showLive";
		var remindState = -2;
		reloadRemain(url,id,remindState); 
	}else if(remindState==5){//活动
		//局部加载活动预警
		var url = "../platform/reloadActivity";
		var id = "#showActivity";
		reloadRemain(url,id); 
	}
}

//局部加载入住预警
function reloadRemain(url,id,remindState){
	$.ajax({
		type:"POST",
		dataType:"html",
		url:url,
		data:{remindState:remindState},
		async:false,
		success:function(data){
			$(id).empty().html(data);  
		}
	});
}
